package com.ctg.payroll2.dao.workflow.imp;

import java.sql.SQLException;
import java.util.List;

import com.ctg.payroll2.bean.ComboData;
import com.ctg.payroll2.bean.filter.WorkflowTaskFilter;
import com.ctg.payroll2.bean.po.PayClass;
import com.ctg.payroll2.bean.po.workflow.FlowInstance;
import com.ctg.payroll2.bean.po.workflow.FlowMaster;
import com.ctg.payroll2.bean.po.workflow.FlowOrgchart;
import com.ctg.payroll2.bean.po.workflow.FlowPayData;
import com.ctg.payroll2.bean.po.workflow.FlowRuninfo;
import com.ctg.payroll2.bean.po.workflow.FlowRunnext;
import com.ctg.payroll2.bean.po.workflow.FlowStep;
import com.ctg.payroll2.bean.po.workflow.FlowStepRun;
import com.ctg.payroll2.dao.workflow.WorkflowTaskDao;
import com.ctg.platform.orm.ibatis.IbatisEntityDao;
import com.ctg.platform.util.Page;

public class WorkflowTaskDaoImp extends IbatisEntityDao implements WorkflowTaskDao {
	private String getNameSpace(){
		return this.getClass().getSimpleName();
	}
	
	public Page queryTask(WorkflowTaskFilter filter){
		return pagedQueryByFilter(this.getClass(), filter,
				".queryTask_count",
				".queryTask_query");
	}
	public Long insertFlowInstance(FlowInstance flowInstance) throws SQLException{
		return (Long)getSqlMapClient().insert(getNameSpace() + ".insertFlowInstance", flowInstance);
	}
	public Long insertFlowRunnext(FlowRunnext flowRunnext) throws SQLException{
		return (Long)getSqlMapClient().insert(getNameSpace() + ".insertFlowRunnext", flowRunnext);
	}
	public Long insertFlowRuninfo(FlowRuninfo flowRuninfo) throws SQLException{
		return (Long)getSqlMapClient().insert(getNameSpace() + ".insertFlowRuninfo", flowRuninfo);
	}
	public int updateFlowInstance(FlowInstance flowInstance) throws SQLException{
		return getSqlMapClient().update(getNameSpace() + ".updateFlowInstance", flowInstance);
	}
	public int updateFlowRunnext(FlowRunnext flowRunnext) throws SQLException{
		return getSqlMapClient().update(getNameSpace() + ".updateFlowRunnext", flowRunnext);
	}
	public Integer querySubCompanyCount(WorkflowTaskFilter filter) throws SQLException{
		return (Integer)getSqlMapClient().queryForObject(getNameSpace() +".querySubCompany_count", filter.getCompany_code());
	}
	public FlowStepRun queryStartFlowStepRun(WorkflowTaskFilter filter) throws SQLException{
		return (FlowStepRun)getSqlMapClient().queryForObject(getNameSpace() +".queryStartFlowStepRun", filter.getCompany_code());
	}
	public FlowStepRun queryFlowStepRun(WorkflowTaskFilter filter) throws SQLException{
		return (FlowStepRun)getSqlMapClient().queryForObject(getNameSpace() +".queryFlowStepRun", filter.getStep_id());
	}
	@SuppressWarnings("unchecked")
	public List<ComboData> querySubordinateByCompanyCode(WorkflowTaskFilter filter) throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".querySubordinateByCompanyCode", filter);
	}
	
	public int getEmployeeCountOfCompany(WorkflowTaskFilter filter)throws SQLException{
		return (Integer)getSqlMapClient().queryForObject(getNameSpace() + ".getEmployeeCountOfCompany", filter);
	}
	
	public int getEmployeeCountOfPayData(WorkflowTaskFilter filter)throws SQLException{
		return (Integer)getSqlMapClient().queryForObject(getNameSpace() + ".getEmployeeCountOfPayData", filter);
	}
	@SuppressWarnings("unchecked")
	public int queryPayLogByPeriod(WorkflowTaskFilter filter)throws SQLException{
		return (Integer)getSqlMapClient().queryForObject(getNameSpace() + ".queryPayLogByPeriod", filter);
	}
	@SuppressWarnings("unchecked")
	public List<ComboData> queryPayTypeByFilter(WorkflowTaskFilter filter)throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".queryPayTypeByFilter", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowMaster queryFlowMaster(WorkflowTaskFilter filter)throws SQLException{
		return (FlowMaster)getSqlMapClient().queryForObject(getNameSpace() + ".queryFlowMaster", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowStep queryStartFlowStep(WorkflowTaskFilter filter)throws SQLException{
		return (FlowStep)getSqlMapClient().queryForObject(getNameSpace() + ".queryStartFlowStep", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowStep queryNextFlowStep(WorkflowTaskFilter filter)throws SQLException{
		return (FlowStep)getSqlMapClient().queryForObject(getNameSpace() + ".queryNextFlowStep", filter);
	}
	@SuppressWarnings("unchecked")
	public String queryApproveMemoByIsId(Long id)throws SQLException{
		List<String> list = getSqlMapClient().queryForList(getNameSpace() + ".queryApproveMemoByIsId", id);
		StringBuffer sb = new StringBuffer();
		for (String str : list) {
			sb.append(str).append("\r\n");
		}
		
		return sb.toString();
	}
	@SuppressWarnings("unchecked")
	public FlowRunnext queryFlowRunnext(WorkflowTaskFilter filter)throws SQLException{
		return (FlowRunnext)getSqlMapClient().queryForObject(getNameSpace() + ".queryFlowRunnext", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowOrgchart queryParentFlowOrgchat(WorkflowTaskFilter filter)throws SQLException{
		return (FlowOrgchart)getSqlMapClient().queryForObject(getNameSpace() + ".queryParentFlowOrgchat", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowInstance queryFlowInstance(WorkflowTaskFilter filter)throws SQLException{
		return (FlowInstance)getSqlMapClient().queryForObject(getNameSpace() + ".queryFlowInstance", filter);
	}
	@SuppressWarnings("unchecked")
	public Integer querySubInstance_count(WorkflowTaskFilter filter)throws SQLException{
		return (Integer)getSqlMapClient().queryForObject(getNameSpace() + ".querySubInstance_count", filter);
	}
	@SuppressWarnings("unchecked")
	public FlowRunnext queryParentRunnext(WorkflowTaskFilter filter)throws SQLException{
		return (FlowRunnext)getSqlMapClient().queryForObject(getNameSpace() + ".queryParentRunnext", filter);
	}
	public int updatePayData(WorkflowTaskFilter filter) throws SQLException{
		return getSqlMapClient().update(getNameSpace() + ".updatePayData", filter);
	}
	@SuppressWarnings("unchecked")
	public List<PayClass> queryPayClassIdFromPayData(WorkflowTaskFilter filter)throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".queryPayClassIdFromPayData", filter);
	}
	@SuppressWarnings("unchecked")
	public List<FlowPayData> queryAreaFromPayData(WorkflowTaskFilter filter)throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".queryAreaFromPayData", filter);
	}
	@SuppressWarnings("unchecked")
	public List<FlowPayData> queryGroupFromPayData(WorkflowTaskFilter filter)throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".queryGroupFromPayData", filter);
	}
	@SuppressWarnings("unchecked")
	public List<FlowPayData> querySubCompany(WorkflowTaskFilter filter)throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".querySubCompany", filter);
	}
}
